package com.ufox.mapper;

import com.ufox.entity.Cartitem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ufox.entity.Result;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 优狐科技-www.hbufox.com
 * @since 2022-06-09
 */
public interface CartitemMapper extends BaseMapper<Cartitem> {

    @Insert("insert into cartitem values(null,#{userId},#{prodId},1)")
    void addCart(@Param("userId") String userId,@Param("prodId") String prodId);

    @Select("SELECT * FROM cartitem WHERE user_id = #{userId}")
    List<Cartitem> findCartItemByUserId(@Param("userId") String userId);

    @Insert("insert into cartitem values(null,#{userId},#{prodId},#{pnum}-1)")
    void insertCart(@Param("userId") String userId,@Param("prodId") String prodId,@Param("pnum") String pnum);

    @Select("SELECT COUNT(id) AS sum  FROM cartitem WHERE user_id = #{userId}")
    String getCountByUserId(@Param("userId") String userId);

}
